<template>
  <div>
    <div class="header">
      <div class="inputItem">
        <div class="title">全部状态</div>
        <div class="inputBox">
          <el-select class="select" v-model="settlementStatus" placeholder="请选择">
            <el-option v-for="item in SettlementStatusArr" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </div>
      </div>
      <div class="inputItem">
        <div class="title">结算单号</div>
        <div class="inputBox">
          <el-input v-model="statementOdd" @keyup.enter.native="searchHttpList1">
          </el-input>
        </div>
      </div>
      <div class="inputItem">
        <div class="title">项目名称</div>
        <div class="inputBox">
          <el-input v-model="projectName" @keyup.enter.native="searchHttpList1">
          </el-input>
        </div>
      </div>
      <div class="inputItem">
        <div class="title">司机姓名</div>
        <div class="inputBox">
          <el-input v-model="driverName" @keyup.enter.native="searchHttpList1">
          </el-input>
        </div>
      </div>
      <div class="inputItem">
        <div class="title">创建时间</div>
        <el-date-picker size="small" v-model="createTime" type="datetimerange" :picker-options="pickerOptions"
          range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" align="right"
          value-format="yyyy-MM-dd HH:mm:ss">
        </el-date-picker>
      </div>
      <!-- 查询 -->
      <div class="Btn_grounp">
        <el-button class="searchBtn" type="primary" size="small" icon="el-icon-search"
          @click="searchHttpList1">筛选</el-button>
        <el-button class="clearBtn" type="plain" size="small" icon="el-icon-refresh-right" @click="CleanUp">清空</el-button>
      </div>
    </div>
    <div class="main">
      <div class="list">
        <el-table :data="records" style="width: 100%" ref="table2">
          <el-table-column align="center" prop="SerialNumber" label="序号" width="70">
            <template slot-scope="scope">
              {{ scope.$index + 1 + Number(size) * (pageCurrent - 1) }}
            </template>
          </el-table-column>
          <el-table-column align="center" prop="transportStatus" label="订单状态" width="90">
            <template slot-scope="scope">
              <div class="tag" v-if="scope.row.settlementStatus == 0">
                <div class="dian"></div>
                <div class="text">已核算</div>
              </div>
              <div class="tag isWait" v-else-if="scope.row.settlementStatus == 1">
                <div class="dian" style="background-color: #f9aa0d"></div>
                <div class="text">待核算</div>
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="statementOdd" label="结算单号" width="220">
          </el-table-column>
          <el-table-column align="center" prop="projectName" label="项目名称">
          </el-table-column>
          <el-table-column align="center" prop="driverName" label="司机姓名">
          </el-table-column>
          <el-table-column align="center" prop="numberplate" label="车辆信息">
          </el-table-column>
          <el-table-column align="center" prop="billAmount" label="司机金额">
          </el-table-column>
          <el-table-column align="center" prop="" label="结算金额">
            <template slot-scope="scope">
              <div v-if="scope.row.settlementAmount != undefined">
                {{
                  scope.row.settlementStatus == 0
                  ? scope.row.settlementAmount
                  : scope.row.settlementAmount == 0
                    ? "--.--"
                    : scope.row.settlementAmount
                }}
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="createTime" label="用车时间" sortable>
          </el-table-column>

          <el-table-column align="center" label="操作">
            <template slot-scope="scope">
              <div>
                <el-button type="text" size="small" @click="
                $router.push(
                  '/orderManagement/MatchDriverSettlement/Details/' +
                  scope.row.driverBillId
                )
                  ">详情</el-button>
                <!-- WaybillManagement/Details/:waybillId -->
              </div>
              <!-- <div>
                <el-button
                    type="text"
                    size="small"
                    v-show="scope.row.settlementStatus == 1"
                >核算</el-button
                >
              </div> -->
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 分页 -->
      <div class="paginationBox">
        <el-pagination class="pagination" background layout="slot,prev, pager, next" :total="data.total * 1"
          :page-size="data.size * 1" :pager-count="5" @current-change="changePages($event)">
          <template slot>
            <span style="
                color: #686868;
                font-size: 12px;
                margin-right: 20px;
                display: inline-block;
              ">共{{ data.total }}条,每页{{ data.size }}条</span>
          </template>
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import httpApi from "@/http";
export default {
  data() {

    return {
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },

      createTime: [],//创建时间
      settlementStatus: "", //运单状态
      BusinessTypeValue: "", //业务类型
      statementOdd: "", //运单编号
      projectName: "", //项目名称
      driverName: "",
      TypeSelected: "",
      records: [], //列表数据
      data: {},
      SerialNumber: "",
      pageCurrent: "1",
      size: "15",
      //全部状态选项
      SettlementStatusArr: [
        { value: "0", label: "已结算" },
        { value: "1", label: "待结算" },
        // { value: "2", label: "已取消" },
      ],
      //   业务类型选项
      BusinessTypeArr: [
        { value: "1", label: "无需配送" },
        { value: "2", label: "未发货" },
        { value: "3", label: "部分发货" },
        { value: "4", label: "已发货" },
        { value: "5", label: "待装运" },
        { value: "6", label: "装运完成" },
        { value: "7", label: "运输中" },
        { value: "8", label: "已送达" },
        { value: "9", label: "完成卸货" },
      ],
    };
  },
  methods: {
    changePages(val) {
      this.pageCurrent = val;
      this.initList();
    },
    initList() {
      // status判定 2:已完成运单, 1:在途运单, 0:待审核运单
      let params = {
        current: this.pageCurrent,
        size: this.size,
      };

      httpApi.SettlementDocApi.getStatementAccountList(params).then((res) => {
        // console.log(res);
        this.data = res.data.data;
        this.records = res.data.data.records;
        // console.log("对账单总数据", this.data);
        // console.log("对账单列表数据", this.records);
        // 前端解决序号


      });
    },
	searchHttpList1(){
		this.pageCurrent=1;
		this.searchHttpList();
	},
    searchHttpList() {
      let params = {
        current: this.pageCurrent,
        size: this.size,
        settlementStatus: this.settlementStatus,
        statementOdd: this.statementOdd,
        name: this.projectName,
        driverName: this.driverName,
        startTime: this.createTime != null ? this.createTime[0] : '', //开始时间
        endTime: this.createTime != null ? this.createTime[1] : '', //结束时间
      };
      httpApi.SettlementDocApi.getStatementAccountList(params).then((res) => {
        // console.log(res);
        this.data = res.data.data;
        this.records = res.data.data.records;
        // console.log("搜索总数据", this.data);
        // console.log("搜索列表数据", this.records);

      });
    },

    CleanUp() {
      this.settlementStatus = "";
      this.projectName = "";
      this.statementOdd = "";
      this.driverName = ""
      this.createTime = [],
        this.searchHttpList1();
    },
    // 记录滚动距离
    scrollEvent(res) {
      this.$route.meta.scrollTop = res.target.scrollTop
    },
  },
  activated() {
    //组件激活时监听表格滚动条位置,
    this.$refs.table2.bodyWrapper.addEventListener('scroll', this.scrollEvent, false)
    // 激活设置滚动位置
    this.$refs.table2.bodyWrapper.scrollTop = this.$route.meta.scrollTop
  },
  beforeRouteLeave(to, from, next) {
    // 为了节省资源，再离开页面的时候关闭对于scroll事件的监听
    this.$refs.table2.bodyWrapper.removeEventListener('scroll', this.scrollEvent)
    next()
  },


  mounted() {
    this.initList();
  },
};
</script>

<style lang="scss" scoped>
.header {
  height: 106px;
  width: 100%;
  background-color: #fff;
  display: flex;
  align-items: center;
  padding: 0 29px;
  margin-bottom: 8px;
  flex-wrap: wrap;

  .Btn_grounp {
    display: flex;

    .searchBtn {
      width: 80px;
      height: 32px;
      color: #fff;
      font-size: 12px;
    }

    .clearBtn {
      width: 80px;
      height: 32px;
      color: #262626;
      font-size: 12px;
    }
  }

  .inputItem {
    display: flex;
    align-items: center;
    margin-right: 70px;

    >.title {
      color: #262626;
      font-size: 12px;
      margin-right: 7px;
    }

    >.inputBox {
      width: 160px;

      .select {
        ::v-deep .el-input__icon {
          line-height: 0;
        }
      }

      ::v-deep .el-input__inner {
        height: 32px;
        font-size: 12px;
      }

      ::v-deep .el-input__inner::placeholder {
        color: #c3c3c3;
        font-size: 12px;
      }
    }
  }
}

.main {
  width: 100%;
  height: calc(100vh - 305px);
  background-color: #fff;

  .list {
    height: calc(100% - 48px);
    width: 100%;
    padding: 0 30px;

    .tag {
      width: 63px;
      height: 28px;
      font-size: 12px;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 4px;
      background-color: #ecf5fe;
      color: #1890ff;
      margin: 0 auto;


      .dian {
        width: 4px;
        height: 4px;
        border-radius: 50%;
        margin-right: 4px;
        background-color: #1890ff;
      }

      &.isWait {
        color: #f9aa0d;
        background-color: #fffce8;
      }
    }

    ::v-deep .el-table__body-wrapper {
      height: calc(100vh - 402px) !important;
      overflow-y: scroll;
    }

    // 表头样式
    ::v-deep .el-table__header th {
      background-color: #f0f6fd;
      color: #262626;
      font-size: 12px;
      font-weight: bold;
      text-align: center;
      height: 48px;
      padding: 0;

      // 表 body的td
      ::v-deep .el-table__body td {
        color: #595959;
        font-size: 12px;
      }
    }

    .stateBtns {
      height: 30px;
      width: 76px;

      ::v-deep .el-button {
        height: 30px;
        width: 76px;
        font-size: 12px;
        border: none;
        display: flex;
        align-items: center;
        justify-content: center;
        line-height: 30px;
      }

      .waitPass {
        background-color: #ecf5fe;
        color: #1890ff;
      }

      .noPass {
        background-color: #fde8e9;
        color: #f7555d;
      }
    }
  }

  .paginationBox {
    width: 100%;
    background-color: #fff;
    display: flex;
    height: 48px;
    padding: 0 30px;

    .pagination {
      height: 48px;
      margin-left: auto;
      display: flex;
      align-items: center;
    }
  }
}
</style>
